﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DLLPC;
using DLLPC.Utilities;
using System.IO;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
using System.Threading;

namespace VisionCore
{
    public class Status_ExcStatus : ProcedureHelper_Exc
    {
        int TimeCount = 0;
        public void Main()
        {

            ExcHomeComp = Kernel.motion.CV1_TrackSW_Y.IsHomeAlready
                       && Kernel.motion.CV2_TrackSW_Y.IsHomeAlready
                       && Kernel.motion.CCD1_X.IsHomeAlready
                       && Kernel.motion.CCD1_Y.IsHomeAlready
                       && Kernel.motion.CCD1_Z.IsHomeAlready
                       && Kernel.motion.CCD2_X.IsHomeAlready
                       && Kernel.motion.CCD2_Y.IsHomeAlready
                       && Kernel.motion.CCD2_Z.IsHomeAlready
                       && Kernel.motion.CV1_Y.IsHomeAlready
                       && Kernel.motion.CV2_Y.IsHomeAlready
                       && Kernel.motion.Insp1_Y.IsHomeAlready
                       && Kernel.motion.Insp2_Y.IsHomeAlready
                       && Kernel.motion.Insp3_Y.IsHomeAlready
                       && Kernel.motion.Insp4_Y.IsHomeAlready ;

            CV1_Cyl_Up = /*ParameterHelper.CV1.Enable &&*/ Kernel.Exc.DI.X022_CV1_Cyl_Up == 1;
            CV1_Cyl_Dn = /*ParameterHelper.CV1.Enable &&*/ Kernel.Exc.DI.X023_CV1_Cyl_Dn == 1;

            CV2_Cyl_Up = /*ParameterHelper.CV2.Enable &&*/ Kernel.Exc.DI.X028_CV2_Cyl_Up == 1;
            CV2_Cyl_Dn = /*ParameterHelper.CV2.Enable &&*/ Kernel.Exc.DI.X029_CV2_Cyl_Dn == 1;

            Insp1_Cyl_Up = /*ParameterHelper.Insp1.Enable &&*/ Kernel.Exc.DI.X030_1_Insp_Cyl_Up == 1;
            Insp1_Cyl_Dn = /*ParameterHelper.Insp1.Enable &&*/ Kernel.Exc.DI.X031_1_Insp_Cyl_Dn == 1;
            Insp1_VacOnn = /*ParameterHelper.Insp1.Enable &&*/ Kernel.Exc.DI.X032_1_Insp_Vac == 1;

            Insp2_Cyl_Up = /*ParameterHelper.Insp2.Enable &&*/ Kernel.Exc.DI.X038_2_Insp_Cyl_Up == 1;
            Insp2_Cyl_Dn = /*ParameterHelper.Insp2.Enable &&*/ Kernel.Exc.DI.X039_2_Insp_Cyl_Dn == 1;
            Insp2_VacOnn = /*ParameterHelper.Insp2.Enable &&*/ Kernel.Exc.DI.X03A_2_Insp_Vac == 1;

            Insp3_Cyl_Up = /*ParameterHelper.Insp3.Enable &&*/ Kernel.Exc.DI.X040_3_Insp_Cyl_Up == 1;
            Insp3_Cyl_Dn = /*ParameterHelper.Insp3.Enable &&*/ Kernel.Exc.DI.X041_3_Insp_Cyl_Dn == 1;
            Insp3_VacOnn = /*ParameterHelper.Insp3.Enable &&*/ Kernel.Exc.DI.X042_3_Insp_Vac == 1;

            Insp4_Cyl_Up = /*ParameterHelper.Insp3.Enable &&*/ Kernel.Exc.DI.X048_4_Insp_Cyl_Up == 1;
            Insp4_Cyl_Dn = /*ParameterHelper.Insp3.Enable &&*/ Kernel.Exc.DI.X049_4_Insp_Cyl_Dn == 1;
            Insp4_VacOnn = /*ParameterHelper.Insp3.Enable &&*/ Kernel.Exc.DI.X04A_4_Insp_Vac == 1;

            SafeDoor1_Lockk = Kernel.Exc.DI.X058_DoorMonitor1 == 1;
            SafeDoor2_Lockk = Kernel.Exc.DI.X059_DoorMonitor2 == 1;


           Insp1_Hard_Existence = /*Kernel.Exc.DI.X033_1_InspCV_Exist1 == 1 &&*/ Kernel.Exc.DI.X034_1_InspCV_Exist2 == 1;
           Insp2_Hard_Existence = /*Kernel.Exc.DI.X03B_2_InspCV_Exist1 == 1 &&*/ Kernel.Exc.DI.X03C_2_InspCV_Exist2 == 1;
           Insp3_Hard_Existence = /*Kernel.Exc.DI.X043_3_InspCV_Exist1 == 1 &&*/ Kernel.Exc.DI.X044_3_InspCV_Exist2 == 1;
           Insp4_Hard_Existence = /*Kernel.Exc.DI.X04B_4_InspCV_Exist1 == 1 &&*/ Kernel.Exc.DI.X04C_4_InspCV_Exist2 == 1;

            Insp1_Hard_Nothing = DelayOn_Empty(1,Kernel.Exc.DI.X033_1_InspCV_Exist1 == 0, Kernel.Exc.DI.X035_1_InspCV_Exist3 == 0, Kernel.Exc.DI.X036_1_InspStage_Exist == 0 , Kernel.Exc.DI.X037_1_InspStage_Stop == 0,10);
            Insp2_Hard_Nothing = DelayOn_Empty(2,Kernel.Exc.DI.X03B_2_InspCV_Exist1 == 0, Kernel.Exc.DI.X03D_2_InspCV_Exist3 == 0, Kernel.Exc.DI.X03E_2_InspStage_Exist == 0 , Kernel.Exc.DI.X03F_2_InspStage_Stop == 0,10);
            Insp3_Hard_Nothing = DelayOn_Empty(3,Kernel.Exc.DI.X043_3_InspCV_Exist1 == 0, Kernel.Exc.DI.X045_3_InspCV_Exist3 == 0, Kernel.Exc.DI.X046_3_InspStage_Exist == 0 , Kernel.Exc.DI.X047_3_InspStage_Stop == 0,10);
            Insp4_Hard_Nothing = DelayOn_Empty(4,Kernel.Exc.DI.X04B_4_InspCV_Exist1 == 0, Kernel.Exc.DI.X04D_4_InspCV_Exist3 == 0, Kernel.Exc.DI.X04E_4_InspStage_Exist == 0 , Kernel.Exc.DI.X04F_4_InspStage_Stop == 0,10);




           //Insp1_Hard_Nothing = Kernel.Exc.DI.X033_1_InspCV_Exist1 == 0 && Kernel.Exc.DI.X035_1_InspCV_Exist3 == 0 && Kernel.Exc.DI.X036_1_InspStage_Exist == 0 && Kernel.Exc.DI.X037_1_InspStage_Stop == 0;
           //Insp2_Hard_Nothing = Kernel.Exc.DI.X03B_2_InspCV_Exist1 == 0 && Kernel.Exc.DI.X03D_2_InspCV_Exist3 == 0 && Kernel.Exc.DI.X03E_2_InspStage_Exist == 0 && Kernel.Exc.DI.X03F_2_InspStage_Stop == 0;
           //Insp3_Hard_Nothing = Kernel.Exc.DI.X043_3_InspCV_Exist1 == 0 && Kernel.Exc.DI.X045_3_InspCV_Exist3 == 0 && Kernel.Exc.DI.X046_3_InspStage_Exist == 0 && Kernel.Exc.DI.X047_3_InspStage_Stop == 0;
           //Insp4_Hard_Nothing = Kernel.Exc.DI.X04B_4_InspCV_Exist1 == 0 && Kernel.Exc.DI.X04D_4_InspCV_Exist3 == 0 && Kernel.Exc.DI.X04E_4_InspStage_Exist == 0 && Kernel.Exc.DI.X04F_4_InspStage_Stop == 0;



            CV1_Presence = ParameterHelper.CV1.Enable && (Kernel.Exc.DI.X021_CV1_Stop == 1 || DryRunMode);
            CV1_Empty = !ParameterHelper.CV1.Enable && (Kernel.Exc.DI.X020_CV1_Exist == 0||Kernel.Exc.DI.X021_CV1_Stop==0);

            CV2_Presence = ParameterHelper.CV2.Enable && (Kernel.Exc.DI.X027_CV2_Stop == 1 || DryRunMode);
            CV2_Empty = !ParameterHelper.CV2.Enable && (Kernel.Exc.DI.X027_CV2_Stop == 0 || Kernel.Exc.DI.X026_CV2_Exist == 0);

            Insp1_Presence = ParameterHelper.Insp1.Enable && (Insp1_Hard_Existence || DryRunMode);
            Insp1_Empty = !ParameterHelper.Insp1.Enable && Insp1_Hard_Nothing;

            Insp2_Presence = ParameterHelper.Insp2.Enable && (Insp2_Hard_Existence || DryRunMode);
            Insp2_Empty = !ParameterHelper.Insp2.Enable&& Insp2_Hard_Nothing;

            Insp3_Presence = ParameterHelper.Insp3.Enable && (Insp3_Hard_Existence || DryRunMode);
            Insp3_Empty = !ParameterHelper.Insp3.Enable && Insp3_Hard_Nothing;

            Insp4_Presence = ParameterHelper.Insp4.Enable && (Insp4_Hard_Existence || DryRunMode);
            Insp4_Empty = !ParameterHelper.Insp4.Enable && Insp4_Hard_Nothing;


            Door_Lock =Kernel.Exc.DI.X058_DoorMonitor1 == 1
                  && Kernel.Exc.DI.X059_DoorMonitor2 == 1
                  && Kernel.Exc.DO.Y058_SafeDoor1_Lock == 1
                  && Kernel.Exc.DO.Y059_SafeDoor2_Lock == 1;


            #region 伺服轴AllowMove
            CV1_Y_AllowMove = Door_Lock;
            CV2_Y_AllowMove = Door_Lock;
            CV1_TrackSW_Y_AllowMove = Door_Lock || Kernel.Exc.DI.X036_1_InspStage_Exist == 0 || Kernel.Exc.DI.X03E_2_InspStage_Exist == 0;
            CV2_TrackSW_Y_AllowMove = Door_Lock || Kernel.Exc.DI.X046_3_InspStage_Exist == 0 || Kernel.Exc.DI.X04E_4_InspStage_Exist == 0;
            CCD1_X_AllowMove = Door_Lock;
            CCD1_Y_AllowMove = Door_Lock;
            CCD1_Z_AllowMove = Door_Lock;
            CCD2_X_AllowMove = Door_Lock;
            CCD2_Y_AllowMove = Door_Lock;
            CCD2_Z_AllowMove = Door_Lock;
            Insp1_Y_AllowMove = Door_Lock;
            Insp2_Y_AllowMove = Door_Lock;
            Insp3_Y_AllowMove = Door_Lock;
            Insp4_Y_AllowMove = Door_Lock;
            //Insp1_RM_Z_AllowMove = Door_Lock;
            //Insp2_RM_Z_AllowMove = Door_Lock;
            //Insp3_RM_Z_AllowMove = Door_Lock;
            //Insp4_RM_Z_AllowMove = Door_Lock;
            #endregion

            #region 数据传递
           

            //Kernel.MarkLocate_ULDST.Marks[0].Mark = new PointRotation.Point(ParameterHelper.CurParam.ULDST.ALG1.X, ParameterHelper.CurParam.ULDST.ALG1.Y);
            //Kernel.MarkLocate_ULDST.Marks[1].Mark = new PointRotation.Point(ParameterHelper.CurParam.ULDST.ALG1.X + ParameterHelper.CurParam.Panel.Info.MarkPitch.X, ParameterHelper.CurParam.ULDST.ALG1.Y - ParameterHelper.CurParam.Panel.Info.MarkPitch.Y);

            if (ManualMode)
            {
                //ULDST_Ext_DieLDPos = ParameterHelper.CurParam.ULDST.Ext_DieLD;
                ULDST_Ext_DieLDPosTab = 0;
            }

            #endregion

            #region 状态清除
            if (ManualMode)
            {
                if (EQ_Reset)
                {
                    SetMarkingParameterComplete = false;
                    SetProgramComplete = false;
                    SetMarkingParameterFail = false;
                    SetProgramFail = false;
                    SetBlockFail = false;
                }
                ULDSTNGTrayFocusChange = false;
                ULDSTNGTrayChangeComplete = false;
                ExcSTCodeScanEnable = false;
            }
           

            

            #endregion

            #region 报警触发
          

            //DelayOnHelper_Exc.ExcSTVacError.Trigger = (Kernel.Exc.DO.Y1C0_ExcST_VacOn==1 && !ExcST_Vac) || (Kernel.Exc.DO.Y1C0_ExcST_VacOn == 0 && ExcST_Vac);
            //DelayOnHelper_Exc.SortSTVacError.Trigger = (Kernel.Exc.DO.Y1CC_SortST_OK_VacON == 1 && !SortST_Vac) || (Kernel.Exc.DO.Y1CC_SortST_OK_VacON == 0 && SortST_Vac);
          
            //DelayOnHelper_Exc.ExcST_DownError.Trigger =Kernel.Exc.DO.Y1C1_ExcST_Up == 0 && (!ExcST_Down || ExcST_Up);
            //DelayOnHelper_Exc.Exc_UpError.Trigger = Kernel.Exc.DO.Y1C4_ExcTR_Down == 0 && (Exc_Down || !Exc_Up);
            //DelayOnHelper_Exc.Exc_DownError.Trigger = Kernel.Exc.DO.Y1C4_ExcTR_Down == 1 && Exc_Up;
            //DelayOnHelper_Exc.Exc_Ms_UpError.Trigger = Kernel.Exc.DO.Y1C6_ExcTR_Ms_Down == 0 && (Exc_MS_Down || !Exc_MS_Up);
            //DelayOnHelper_Exc.Exc_Ms_DownError.Trigger = Kernel.Exc.DO.Y1C6_ExcTR_Ms_Down == 1 && (!Exc_MS_Down || Exc_MS_Up);
            //DelayOnHelper_Exc.ExcTR_CloseError.Trigger = Kernel.Exc.DO.Y1C7_ExcTR_Close == 0 && (!ExcTR_Close || ExcTR_Open);
            //DelayOnHelper_Exc.ExcTR_OpenError.Trigger = Kernel.Exc.DO.Y1C7_ExcTR_Close == 1 && !ExcTR_Open;
            //DelayOnHelper_Exc.SortST_UpError.Trigger = Kernel.Exc.DO.Y1CD_SortST_Up == 1 && (!SortST_Up || SortST_Down);
            //DelayOnHelper_Exc.SortST_DownError.Trigger = Kernel.Exc.DO.Y1CD_SortST_Up == 0 && (SortST_Up || !SortST_Down);
            //DelayOnHelper_Exc.SortST_NG_UpError.Trigger = Kernel.Exc.DO.Y205_SortST_NG_Up == 1 && (!SortST_NG_Up || SortST_NG_Down);
            //DelayOnHelper_Exc.SortST_NG_DownError.Trigger = Kernel.Exc.DO.Y205_SortST_NG_Up == 0 && (SortST_NG_Up || !SortST_NG_Down);

            DelayOnHelper_Exc.CV1_UpError.Trigger = Kernel.Exc.DO.Y022_1_CV_Cyl_Up == 1 && (!CV1_Cyl_Up || CV1_Cyl_Dn);
            DelayOnHelper_Exc.CV2_UpError.Trigger = Kernel.Exc.DO.Y022_1_CV_Cyl_Up == 0 && (CV1_Cyl_Up || !CV1_Cyl_Dn);
            DelayOnHelper_Exc.CV1_DnError.Trigger = Kernel.Exc.DO.Y028_2_CV_Cyl_Up == 1 && (!CV2_Cyl_Up || CV2_Cyl_Dn);
            DelayOnHelper_Exc.CV2_DnError.Trigger = Kernel.Exc.DO.Y028_2_CV_Cyl_Up == 0 && (CV2_Cyl_Up || !CV2_Cyl_Dn);
            DelayOnHelper_Exc.Insp1_UpError.Trigger = Kernel.Exc.DO.Y030_1_Insp_Cyl_Up==1&&(Insp1_Cyl_Dn||!Insp1_Cyl_Up);
            DelayOnHelper_Exc.Insp1_DnError.Trigger = Kernel.Exc.DO.Y030_1_Insp_Cyl_Up == 0 && (!Insp1_Cyl_Dn || Insp1_Cyl_Up);
            DelayOnHelper_Exc.Insp2_UpError.Trigger = Kernel.Exc.DO.Y038_2_Insp_Cyl_Up == 1 && (Insp2_Cyl_Dn || !Insp2_Cyl_Up);
            DelayOnHelper_Exc.Insp2_DnError.Trigger = Kernel.Exc.DO.Y038_2_Insp_Cyl_Up == 0 && (!Insp2_Cyl_Dn || Insp2_Cyl_Up);
            DelayOnHelper_Exc.Insp3_UpError.Trigger = Kernel.Exc.DO.Y040_3_Insp_Cyl_Up == 1 && (Insp3_Cyl_Dn || !Insp3_Cyl_Up);
            DelayOnHelper_Exc.Insp3_DnError.Trigger = Kernel.Exc.DO.Y040_3_Insp_Cyl_Up == 0 && (!Insp3_Cyl_Dn || Insp3_Cyl_Up);
            DelayOnHelper_Exc.Insp4_UpError.Trigger = Kernel.Exc.DO.Y048_4_Insp_Cyl_Up == 1 && (Insp4_Cyl_Dn || !Insp4_Cyl_Up);
            DelayOnHelper_Exc.Insp4_DnError.Trigger = Kernel.Exc.DO.Y048_4_Insp_Cyl_Up == 0 && (!Insp4_Cyl_Dn || Insp4_Cyl_Up);




            #endregion

            #region Alarm
            Alarms.PowerOFF = Kernel.Exc.DI.X050 == 0;
            Alarms.Door1_Open = Kernel.Exc.DI.X058_DoorMonitor1 == 0;
            Alarms.Door2_Open = Kernel.Exc.DI.X059_DoorMonitor2 == 0;
           
            Alarms.EMO1_Error = Kernel.Exc.DI.X050 == 0;

            Alarms.CV1_Y_IsHomeAlready = !Kernel.motion.CV1_Y.IsHomeAlready;
            Alarms.CV1_Y_Alarm = Kernel.motion.CV1_Y.AxisMotionIO.ALM == 1;
            Alarms.CV1_Y_LMT_N = Kernel.motion.CV1_Y.AxisMotionIO.LMT_N != 0;
            Alarms.CV1_Y_LMT_P = Kernel.motion.CV1_Y.AxisMotionIO.LMT_P != 0;
            Alarms.CV1_Y_ErrorStop = Kernel.motion.CV1_Y.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;

            Alarms.CV1_TrackSW_Y_IsHomeAlready = !Kernel.motion.CV1_TrackSW_Y.IsHomeAlready;
            Alarms.CV1_TrackSW_Y_Alarm = Kernel.motion.CV1_TrackSW_Y.AxisMotionIO.ALM == 1;
            Alarms.CV1_TrackSW_Y_LMT_N = Kernel.motion.CV1_TrackSW_Y.AxisMotionIO.LMT_N != 0;
            Alarms.CV1_TrackSW_Y_LMT_P = Kernel.motion.CV1_TrackSW_Y.AxisMotionIO.LMT_P != 0;
            Alarms.CV1_TrackSW_Y_ErrorStop = Kernel.motion.CV1_TrackSW_Y.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;

            Alarms.CV2_Y_IsHomeAlready = !Kernel.motion.CV2_Y.IsHomeAlready;
            Alarms.CV2_Y_Alarm = Kernel.motion.CV2_Y.AxisMotionIO.ALM == 1;
            Alarms.CV2_Y_LMT_N = Kernel.motion.CV2_Y.AxisMotionIO.LMT_N != 0;
            Alarms.CV2_Y_LMT_P = Kernel.motion.CV2_Y.AxisMotionIO.LMT_P != 0;
            Alarms.CV2_Y_ErrorStop = Kernel.motion.CV2_Y.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;

            Alarms.CV2_TrackSW_Y_IsHomeAlready = !Kernel.motion.CV2_TrackSW_Y.IsHomeAlready;
            Alarms.CV2_TrackSW_Y_Alarm = Kernel.motion.CV2_TrackSW_Y.AxisMotionIO.ALM == 1;
            Alarms.CV2_TrackSW_Y_LMT_N = Kernel.motion.CV2_TrackSW_Y.AxisMotionIO.LMT_N != 0;
            Alarms.CV2_TrackSW_Y_LMT_P = Kernel.motion.CV2_TrackSW_Y.AxisMotionIO.LMT_P != 0;
            Alarms.CV2_TrackSW_Y_ErrorStop = Kernel.motion.CV2_TrackSW_Y.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;

            Alarms.CCD1_X_IsHomeAlready = !Kernel.motion.CCD1_X.IsHomeAlready;
            Alarms.CCD1_X_Alarm = Kernel.motion.CCD1_X.AxisMotionIO.ALM == 1;
            Alarms.CCD1_X_LMT_N = Kernel.motion.CCD1_X.AxisMotionIO.LMT_N != 0;
            Alarms.CCD1_X_LMT_P = Kernel.motion.CCD1_X.AxisMotionIO.LMT_P != 0;
            Alarms.CCD1_X_ErrorStop = Kernel.motion.CCD1_X.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;

            Alarms.CCD1_Y_IsHomeAlready = !Kernel.motion.CCD1_Y.IsHomeAlready;
            Alarms.CCD1_Y_Alarm = Kernel.motion.CCD1_Y.AxisMotionIO.ALM == 1;
            Alarms.CCD1_Y_LMT_N = Kernel.motion.CCD1_Y.AxisMotionIO.LMT_N != 0;
            Alarms.CCD1_Y_LMT_P = Kernel.motion.CCD1_Y.AxisMotionIO.LMT_P != 0;
            Alarms.CCD1_Y_ErrorStop = Kernel.motion.CCD1_Y.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;

            Alarms.CCD1_Z_IsHomeAlready = !Kernel.motion.CCD1_Z.IsHomeAlready;
            Alarms.CCD1_Z_Alarm = Kernel.motion.CCD1_Z.AxisMotionIO.ALM == 1;
            Alarms.CCD1_Z_LMT_N = Kernel.motion.CCD1_Z.AxisMotionIO.LMT_N != 0;
            Alarms.CCD1_Z_LMT_P = Kernel.motion.CCD1_Z.AxisMotionIO.LMT_P != 0;
            Alarms.CCD1_Z_ErrorStop = Kernel.motion.CCD1_Z.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;

            Alarms.CCD2_X_IsHomeAlready = !Kernel.motion.CCD2_X.IsHomeAlready;
            Alarms.CCD2_X_Alarm = Kernel.motion.CCD2_X.AxisMotionIO.ALM == 1;
            Alarms.CCD2_X_LMT_N = Kernel.motion.CCD2_X.AxisMotionIO.LMT_N != 0;
            Alarms.CCD2_X_LMT_P = Kernel.motion.CCD2_X.AxisMotionIO.LMT_P != 0;
            Alarms.CCD2_X_ErrorStop = Kernel.motion.CCD2_X.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;

            Alarms.CCD2_Y_IsHomeAlready = !Kernel.motion.CCD2_Y.IsHomeAlready;
            Alarms.CCD2_Y_Alarm = Kernel.motion.CCD2_Y.AxisMotionIO.ALM == 1;
            Alarms.CCD2_Y_LMT_N = Kernel.motion.CCD2_Y.AxisMotionIO.LMT_N != 0;
            Alarms.CCD2_Y_LMT_P = Kernel.motion.CCD2_Y.AxisMotionIO.LMT_P != 0;
            Alarms.CCD2_Y_ErrorStop = Kernel.motion.CCD2_Y.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;

            Alarms.CCD2_Z_IsHomeAlready = !Kernel.motion.CCD2_Z.IsHomeAlready;
            Alarms.CCD2_Z_Alarm = Kernel.motion.CCD2_Z.AxisMotionIO.ALM == 1;
            Alarms.CCD2_Z_LMT_N = Kernel.motion.CCD2_Z.AxisMotionIO.LMT_N != 0;
            Alarms.CCD2_Z_LMT_P = Kernel.motion.CCD2_Z.AxisMotionIO.LMT_P != 0;
            Alarms.CCD2_Z_ErrorStop = Kernel.motion.CCD2_Z.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;

            Alarms.Insp1_Y_IsHomeAlready = !Kernel.motion.Insp1_Y.IsHomeAlready;
            Alarms.Insp1_Y_Alarm = Kernel.motion.Insp1_Y.AxisMotionIO.ALM == 1;
            Alarms.Insp1_Y_LMT_N = Kernel.motion.Insp1_Y.AxisMotionIO.LMT_N != 0;
            Alarms.Insp1_Y_LMT_P = Kernel.motion.Insp1_Y.AxisMotionIO.LMT_P != 0;
            Alarms.Insp1_Y_ErrorStop = Kernel.motion.Insp1_Y.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;


            Alarms.Insp2_Y_IsHomeAlready = !Kernel.motion.Insp2_Y.IsHomeAlready;
            Alarms.Insp2_Y_Alarm = Kernel.motion.Insp2_Y.AxisMotionIO.ALM == 1;
            Alarms.Insp2_Y_LMT_N = Kernel.motion.Insp2_Y.AxisMotionIO.LMT_N != 0;
            Alarms.Insp2_Y_LMT_P = Kernel.motion.Insp2_Y.AxisMotionIO.LMT_P != 0;
            Alarms.Insp2_Y_ErrorStop = Kernel.motion.Insp2_Y.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;


            Alarms.Insp3_Y_IsHomeAlready = !Kernel.motion.Insp3_Y.IsHomeAlready;
            Alarms.Insp3_Y_Alarm = Kernel.motion.Insp1_Y.AxisMotionIO.ALM == 1;
            Alarms.Insp3_Y_LMT_N = Kernel.motion.Insp1_Y.AxisMotionIO.LMT_N != 0;
            Alarms.Insp3_Y_LMT_P = Kernel.motion.Insp1_Y.AxisMotionIO.LMT_P != 0;
            Alarms.Insp3_Y_ErrorStop = Kernel.motion.Insp3_Y.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;


            Alarms.Insp4_Y_IsHomeAlready = !Kernel.motion.Insp4_Y.IsHomeAlready;
            Alarms.Insp4_Y_Alarm = Kernel.motion.Insp1_Y.AxisMotionIO.ALM == 1;
            Alarms.Insp4_Y_LMT_N = Kernel.motion.Insp1_Y.AxisMotionIO.LMT_N != 0;
            Alarms.Insp4_Y_LMT_P = Kernel.motion.Insp1_Y.AxisMotionIO.LMT_P != 0;
            Alarms.Insp4_Y_ErrorStop = Kernel.motion.Insp4_Y.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;

                        
            Alarms.Enter_CV1_ErrorStop = Kernel.motion.CV1_Driver.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;
            Alarms.Enter_CV2_ErrorStop = Kernel.motion.CV2_Driver.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;
            Alarms.Insp1_CV1_ErrorStop = Kernel.motion.Insp1_CV1.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;
            Alarms.Insp2_CV1_ErrorStop = Kernel.motion.Insp2_CV1.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;
            Alarms.Insp3_CV1_ErrorStop = Kernel.motion.Insp3_CV1.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;
            Alarms.Insp4_CV1_ErrorStop = Kernel.motion.Insp4_CV1.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;
            Alarms.Insp1_CV2_ErrorStop = Kernel.motion.Insp1_CV2.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;
            Alarms.Insp2_CV2_ErrorStop = Kernel.motion.Insp2_CV2.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;
            Alarms.Insp3_CV2_ErrorStop = Kernel.motion.Insp3_CV2.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;
            Alarms.Insp4_CV2_ErrorStop = Kernel.motion.Insp4_CV2.axis.State == Advantech.Motion.AxisState.STA_AX_ERROR_STOP;
            #endregion

            #region Wainnings
            Warnings.CV1_PresenceError = DelayOnHelper_Exc.CV1_PresenceError.blnReturn;
            Warnings.CV2_PresenceError = DelayOnHelper_Exc.CV1_PresenceError.blnReturn;
            Warnings.Insp1_PresenceError = DelayOnHelper_Exc.Insp1_PresenceError.blnReturn;
            Warnings.Insp2_PresenceError = DelayOnHelper_Exc.Insp2_PresenceError.blnReturn;
            Warnings.Insp3_PresenceError = DelayOnHelper_Exc.Insp3_PresenceError.blnReturn;
            Warnings.Insp4_PresenceError = DelayOnHelper_Exc.Insp4_PresenceError.blnReturn;
           
            Warnings.Insp1_VacError = DelayOnHelper_Exc.Insp1_VacError.blnReturn;
            Warnings.Insp2_VacError = DelayOnHelper_Exc.Insp2_VacError.blnReturn;
            Warnings.Insp3_VacError = DelayOnHelper_Exc.Insp3_VacError.blnReturn;
            Warnings.Insp4_VacError = DelayOnHelper_Exc.Insp4_VacError.blnReturn;

       #endregion
        }

        //public DelayON(bool B1, bool B2, bool B3, bool B4)
        //{
        //    _B1 = B1;
        //    _B2 = B2;
        //    _B3 = B3;
        //    _B4 = B4;
        //}


        int Insp1Delay = 0;
        int Insp2Delay = 0;
        int Insp3Delay = 0;
        int Insp4Delay = 0;       
        public bool DelayOn_Empty(int idx, bool B1, bool B2, bool B3, bool B4,int data)
        {
            if (idx == 1)
            {
                if ((B1 && B2 && B3 && B4))
                {
                    if (Insp1Delay > data) { return true; }
                    else
                    {
                        Insp1Delay++;
                        return false;
                    }
                       
                }
                else
                {
                    Insp1Delay=0;
                    return false;
                }
            }
            else if (idx == 2)
            {
                if ((B1 && B2 && B3 && B4))
                {
                    if (Insp2Delay > data) { return true; }
                    else
                    {
                        Insp2Delay++;
                        return false;
                    }

                }
                else
                {
                    Insp2Delay = 0;
                    return false;
                }
            }
            else if (idx == 3)
            {
                if ((B1 && B2 && B3 && B4))
                {
                    if (Insp3Delay > data) { return true; }
                    else
                    {
                        Insp3Delay++;
                        return false;
                    }

                }
                else
                {
                    Insp3Delay = 0;
                    return false;
                }
            }
            else if (idx == 4)
            {
                if ((B1 && B2 && B3 && B4))
                {
                    if (Insp4Delay > data) { return true; }
                    else
                    {
                        Insp4Delay++;
                        return false;
                    }

                }
                else
                {
                    Insp4Delay = 0;
                    return false;
                }
            }
            else
                return false;
        }



        public class DelayON
        {
            bool _B1;
            bool _B2;
            bool _B3;
            bool _B4;
            int TimeCount = 0;

            public DelayON(bool B1, bool B2, bool B3, bool B4)
            { 
                _B1 = B1;
                _B2 = B2;
                _B3 = B3;
                _B4 = B4;
            }

            public bool DelayOn()
            {
                if (_B1 && _B2 && _B3 && _B4 && TimeCount > 10000)
                {                    
                    return true;
                }
                else
                {
                    TimeCount++;
                    return false;
                }
            }
        }      
    }    
}
